Skip to content

Find Duplicate ​

Find Duplicate — LeetCode

An array of n + 1 integers in the range 1..n has exactly one repeated number. Find it without modifying the array and in O(1) space.

Approach ​

Treat the array like a linked list. Each value at each position is like a pointer to the next node. This will create a chain if there are duplicates.

Use Floyd's Rabbit and Turtle Algorithm to find the start of the cycle.

Remarks ​